package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.RequestWardHandler;
import com.cungmua.app.model.request.WardRequest;
import com.cungmua.app.model.response.WardResponse;
import com.cungmua.app.net.CungMuaAPI;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 6/25/14.
 */
public class RequestWardTask extends AuthenticatedTask<WardRequest, Void, WardResponse> {

    private final RequestWardHandler handler;
    private final Context context;

    public RequestWardTask(Context context, RequestWardHandler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected WardResponse doInBackground() throws RetrofitError {
        WardRequest request = params[0];

        return CungMuaAPI.getService().getListWard(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(WardResponse wardResponse) {
        handler.onListWard(wardResponse);
    }
}
